<template>
	<view>
		<view class="uni-padding-wrap">
			<uni-section title="工单详情列表" type="line">
				<view v-for="(item ,index) in gdcrderlisttemp" :index="index" :key="index">
					<uni-card v-if="item.gdzt == '2'" title="处理工单" :extra="item._add_time_str">
						<p>单号:<text class="uni-body">{{item.gdh}}</text></p>
						<p>项目:<text class="uni-body">{{item.bxxm}}</text></p>
						<p>位置:<text class="uni-body">{{item.bxld}}</text></p>
						<p>描述:<text class="uni-body">{{item.bxms}}</text></p>
						<p>姓名:<text class="uni-body">{{item.xm}}</text></p>
						<p>电话:<text class="uni-body">{{item.bxdh}}</text></p>
						<p v-if="jjbxdh" @click="MymakePhoneCall(jjbxdh)">紧急电话:<text class="uni-body">{{jjbxdh}}</text></p>
						<p v-if="item.imgs"><text class="uni-body">图片:</text></p>
						<view v-if="item.imgs" :key="indexz" class="imgstt" v-for="(img,indexz) in item.imgs">
							<image @click="imgyl(item.imgs,indexz)" style="width: 80px;height: 80px; background-color: #eeeeee;" :src="img" ></image>
						</view>
						<fieldset v-if="item.sfobj" class="layui-elem-field layui-field-title">
						  <legend>维修师傅</legend>
						</fieldset>
						<p v-if="item.sfobj">师傅:<text class="uni-body">{{item.sfobj.name}}</text></p>
						<p v-if="item.sfobj" @click="MymakePhoneCall(item.sfobj.dh)"><view class='cu-tag'>电话</view><text class="uni-body">{{item.sfobj.dh}}</text></p>
						<p v-if="item.sfobj" >处理时间:<uni-dateformat :date="item.sfobj.sj"></uni-dateformat></p>
						<button v-if="!tpsc" style="margin: 10px;" class="btnaaa" type="primary" @click="upload001(item)">上传处理信息</button>
					</uni-card>
				</view>
			</uni-section>
			<uni-section v-if="tpsc" title="图片上传" type="line" style="margin-bottom: 50rpx;">
				<uni-file-picker 
					ref="files"
					:auto-upload="false"
					:sizeType="sizeType"
					v-model="imageValue"  
					file-mediatype="image"
					:image-styles="imageStyles"
					mode="grid"
					file-extname="png,jpg,webp,bmp"
					:limit="9"
					@progress="progress" 
					@success="success" 
					@fail="fail" 
					@select="select"
				/>
				<view class="cu-form-group margin-top">
					<textarea maxlength="200" v-model="wxbz" placeholder="修为备注"></textarea>
				</view>
				<button v-if="imabtn" style="margin: 0px 10px 20px 10px;" class="btnaaa" type="primary" @click="upload00()">上传</button>
			</uni-section>
			<page-foot foot="报修表"></page-foot>
		</view>
	</view>
</template>


<script>
	var _this;
	var vk = uni.vk;
	import uniFilePicker from "@/pages_modules/components/uni-file-picker/uni-file-picker";
	import UniCard from "@/pages_modules/components/uni-card/uni-card";
	import uniDateformat from "@/pages_modules/components/uni-dateformat/uni-dateformat";
	export default {
		components: {UniCard,uniDateformat,uniFilePicker},
		data() {
			// 页面数据变量
			return {
				options:{},
				userinfo:{},
				gdcrderlisttemp:null,
				gdcrderlist:null,
				tpsc:false,
				imabtn:false,
				imageStyles:{
					border:{
						color:"#2F4056"
					}
				},
				imageValue:[],
				wximg:[],
				wxbz:'',
				adults:null,
				sizeType:['compressed'],
			}
		},
		//销毁之前
		beforeDestroy() {
			
		},
		// 监听 - 页面每次【加载时】执行(如：前进) await
		async onLoad(options = {}) {
			_this = this;
			vk = uni.vk;
			this.options = options;
			
			//获取用户信息
			this.userinfo = vk.getVuex('$user.userInfo');
			await this.getbxgdlist();
		},
		// 监听 - 页面【首次渲染完成时】执行。注意如果渲染速度快，会在页面进入动画完成前触发
		onReady(){
			
		},
		// 监听 - 页面每次【显示时】执行(如：前进和返回) (页面每次出现在屏幕上都触发，包括从下级页面点返回露出当前页面)
		onShow() {
			
		},
		// 监听 - 页面每次【隐藏时】执行(如：返回)
		onHide() {
			
		},
		// 监听 - 点击右上角转发时
		onShareAppMessage(options) {
			
		},
		// 函数
		methods: {
			select(e){
				//console.log(e)
				this.imabtn = true
			},
			progress(e){
				//console.log(e)
			},
			fail(e){
				//console.log(e)
			},
			success(e){
				//uni.showToast({title:"上传完毕", icon:"none"});
				//console.log(e)
				//this.fccc = true
				_this.imageValue.forEach(item =>{
					delete item.extname
					delete item.fileType
					delete item.image
					delete item.fileID
					delete item.name
					delete item.size
					delete item.path
					delete item.uuid
					delete item.status
					delete item.cloudPath
				})
				//_this.valiFormData.imgs = _this.imageValue
				
				_this.wximg = _this.imageValue
				console.log('imageValue',_this.imageValue)
				console.log('wximg',_this.wximg)
			},
			upload001(item){
				this.tpsc = true;
				this.adults = this.gdcrderlisttemp.filter(function(gd) {  
				  return gd._id == item._id;  
				});  
				this.gdcrderlisttemp = this.adults 
				
			},
			async upload00(){
				//console.log(this.adults)
				let adultss = this.adults[0]
				await this.$refs.files.upload();
				if(_this.wximg){
					adultss.wximg = [];
					for (let i = 0; i < _this.wximg.length; i++) {
						adultss.wximg.push(_this.wximg[i].url)
					}
				}
				adultss.wxbz = _this.wxbz
				await vk.callFunction({
					url: 'client/gsxy/xybx/pub/xybxapi.updateGsxyyglist',
					data: {...adultss}
				}).then((data) => {
					console.log('xybxapi.gsxyyglist:',data)
				}).catch((err) => {});
				
				await this.getbxgdlist();
				adultss.wximg = [];
				adultss.wxbz = '';
				
			},
			imgyl(listy,i){
				uni.previewImage({
					current:i,
					urls: listy,
					longPressActions: {
						itemList: ['发送给朋友', '保存图片', '收藏'],
						success: function(data) {
							//console.log('选中了第' + (data.tapIndex + i) + '个按钮,第' + (data.index + i) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			},
			getbxgdlist(){
				return vk.callFunction({
					url: 'client/gsxy/xybx/pub/xybxapi.gsxyyglist',
					data: {dh:this.userinfo.mobile}
				}).then((data) => {
					this.gdcrderlist = data.list
					this.gdcrderlisttemp = data.list
					this.tpsc = false
				}).catch((err) => {});
			},
			MymakePhoneCall(ipen){
				uni.makePhoneCall({
					phoneNumber: ipen 
				});
			},
		},
		// 监听器
		watch:{
			
		},
		// 计算属性
		computed:{
			
		}
	}
</script>
<style lang="scss" scoped>
	.imgstt{
		padding: 6px;
		display: inline-grid;
		flex-wrap: wrap;
	}
	
</style>